package leetcode_500;

import java.util.Random;

public class ImplementRand10UsingRand7_470_ {
	public static void main(String[] args) {
		System.out.println(new Random().nextInt(7));
	}
	
	 public int rand10() {
		 int i = ( rand7() -1 ) * 7 + rand7()- 1; // i 是0-48的等概率数
		 if(i>=40)
			 return rand10();
		 return i%40+1;
	 }
	 
	 public int rand7() {
		 return new Random().nextInt(7)+1;
	 }
}
